Bookmark and Bookmarkable Properties Example
This example uses the Bookmark and Bookmarkable properties to let the user flag a record in a Recordset and return to it later.
Sub BookmarkX()
Dim dbsNorthwind As Database
Dim rstCategories As Recordset
Dim strMessage As String
Dim intCommand As Integer
Dim varBookmark As Variant
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstCategories = _
dbsNorthwind.OpenRecordset("Categories", _
dbOpenSnapshot)
With rstCategories
If .Bookmarkable = False Then
Debug.Print "Recordset is not Bookmarkable!"
Else
' Populate Recordset.
.MoveLast
.MoveFirst
Do While True
' Show information about current record and get
' user input.
strMessage = "Category: " & !CategoryName & _
" (record " & (.AbsolutePosition + 1) & _
" of " & .RecordCount & ")" & vbCr & _
"Enter command:" & vbCr & _
"[1 - next / 2 - previous /" & vbCr & _
"3 - set bookmark / 4 - go to bookmark]"
intCommand = Val(InputBox(strMessage))
Select Case intCommand
' Move forward or backward, trapping for BOF
' or EOF.
Case 1
.MoveNext
If .EOF Then .MoveLast
Case 2
.MovePrevious
If .BOF Then .MoveFirst
' Store the bookmark of the current record.
Case 3
varBookmark = .Bookmark
' Go to the record indicated by the stored
' bookmark.
Case 4
If IsEmpty(varBookmark) Then
MsgBox "No Bookmark set!"
Else
.Bookmark = varBookmark
End If
Case Else
Exit Do
End Select
Loop
End If
.Close
End With
dbsNorthwind.Close
End Sub